package com.zsummer.demo.cloudseataservice1;

import com.zsummer.demo.cloudseataservice1.feign.StockService;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author zsummer
 * @since 2022/2/14
 */
@Service
public class OrderService {

    @Autowired
    private StockService stockService;

    @Autowired
    private OrderDao orderDao;

    @GlobalTransactional
    public void order(String productName, int count) {
        // 插入订单
        orderDao.order(productName, count);
        // 远程调用扣减库存服务
        stockService.deductStock(productName, count);
        throw new RuntimeException("订单服务失败");
    }
}
